<?php include_once('header.php');?>
	<div class="main-content">
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			<ul class="breadcrumb">
				<li>
					<i class="icon-home home-icon"></i>
					会员管理
				</li>
				<li>
					会员列表
				</li>
			</ul>
		</div>
		<div class="page-content">
			<div class="page-header">
				<h1 class="blue"><i class="icon-edit"></i> 推荐会员信息</h1>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<form class="form-horizontal" enctype="multipart/form-data" role="form" method="post" onkeydown="if(event.keyCode==13){return false;}" action="/admin/user/add"  onsubmit="return check()">
						
                                                <div class="form-group">
							<label for="title" class="col-sm-1 control-label">推荐人:</label>
							<div class="col-sm-6">
                                                            <input type="text" class="form-control" name="parent_true_name"  readonly="readonly"  value="<?php echo $parent_true_name; ?>">
                                                            <input type="hidden" class="form-control" name="parent_id" value="<?php echo $parent_id; ?>">
                                                            <input type="hidden" class="form-control" id="error_msg" name="error_msg" value="<?php echo $error_msg; ?>">
															
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">供位:</label>
							<div class="col-sm-6">
								<?php if($is_admin =='admin') {?>
								<select name="fora_id" style="float: left;height: 34px;" id="fora_id"  onchange="$('#csg').val('');" >
									<?php

										foreach ($fora as $key => $value) {

											echo ' <option value="' . $value['id'] . '">' . $value['name'] . '</option>';

										}

									?>
								</select>
								<?php }?>
								<input type="text" class="form-control" id="csg" name="csg" <?php if($is_admin =='admin'){?>placeholder=" 请输入供区名字或者供区编码"  style="width:55%;    display: inline-block;" <?php }else { ?>placeholder=" 请输入供区名字或者供区编码"<?php }?> value="<?php if($is_admin =='user'){ echo 'CSG';}?>">
								<?php if($is_admin =='admin') {?><a  id="check_fora" class="btn btn-primary" style="padding: 1px 2px;width: 40px; ">检索</a><?php }?>
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">登录帐户:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="username" name="username" onblur="xietruename()"  value="">
							</div>
						</div>													
						<div class="form-group">
							<label  class="col-sm-1 control-label">密码:</label>
							<div class="col-sm-4">
								<input type="password" class="form-control" id="password1" name="password1" value="123456">
							</div>
						</div>
                                                <div class="form-group">
							<label  class="col-sm-1 control-label">二级密码:</label>
							<div class="col-sm-4">
								<input type="password" class=
                                                                       
                                                                       "form-control" id="password2" name="password2" value="123456">
							</div>
						</div>
						 <div class="form-group">
								<label for="title" class="col-sm-1 control-label">报单时间</label>
								<div class="col-sm-2">
									 <input type="text" class="Wdate form-control" name="s_time" value="<?=$now_time?>" id="d412" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
								</div>
							</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">姓名:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="true_name" name="true_name" value="">
							</div>
						</div>
                                                <div class="form-group">
							<label for="title" class="col-sm-1 control-label">费用:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="price" name="price"<?php if($is_admin !='admin'){echo 'readonly="readonly"';}?> value="<?php echo $system_config['price'];?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">手机号码:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="phone" name="phone" value="">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">联系地址:</label>
							<div class="col-sm-6">				
								<select name="province" id="province">
									<?php 
										foreach($area_list as $key => $value) {
											if($value['areano'] == $area_array[0]) {
												echo ' <option value="'.$value['areano'].','.$value['areaname'].'" selected = "selected">'.$value['areaname'].'</option>';
											}else {
												echo ' <option value="'.$value['areano'].','.$value['areaname'].'">'.$value['areaname'].'</option>';
											}									
										}
									
									?>
								</select>						 
								<select name="city" id="city">						 
									<?php 
										foreach($city_list as $key => $value) {
											if($value['areano'] == $area_array[1]) {
												echo ' <option value="'.$value['areano'].','.$value['areaname'].'" selected = "selected">'.$value['areaname'].'</option>';
											}else {
												echo ' <option value="'.$value['areano'].','.$value['areaname'].'">'.$value['areaname'].'</option>';
											}									
										}
									
									?>
								</select>					 
								<select name="county" id="county">							  
									<?php 
										foreach($county_list as $key => $value) {
											if($value['areano'] == $area_array[2]) {
												echo ' <option value="'.$value['areano'].','.$value['areaname'].'" selected = "selected">'.$value['areaname'].'</option>';
											}else {
												echo ' <option value="'.$value['areano'].','.$value['areaname'].'">'.$value['areaname'].'</option>';
											}									
										}
									
									?>
								</select>
							</div>							
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">详细地址:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="address" name="address" value="">
							</div>
						</div>
                        <input type="hidden" class="input" id="zhuangtai" value="<?php echo $zhuangtai;?>" >
                        <?php if($zhuangtai =='已解锁'){?>
                        <div class="form-group">
                            <label for="title" class="col-sm-1 control-label">是否解锁:</label>
                            <div class="col-sm-6">
                                <label>
                                    <input type="radio" class="input" name="zhuangtai"checked="checked" value="1" >是</input>
                                    <input type="radio" class="input" name="zhuangtai" value="0">否</input>
                                </label>

                            </div>
                        </div>
                        <?php }?>
                        <div class="form-group">
                            <label for="title" class="col-sm-1 control-label">按锁计算:</label>
                            <div class="col-sm-6">
                                <label>
                                    <input type="radio" class="input" name="asjs" checked="checked" onchange="asjsch()" value="1" >是</input>
                                    <input type="radio" class="input" name="asjs" onchange="asjsch()"  value="0">否</input>
                                </label>

                            </div>
                        </div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">备注:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="remark" name="remark" value="">
							</div>
						</div>
					 	<div class="form-group">
					   		<div class="col-sm-offset-1 col-sm-10">
                                                            <button type="submit" id="submit" class="btn btn-primary">确定</button>
                                                            <input style="display: none;"type="button" />
								<button type="submit" id="cancel" class="btn btn-primary">取消</button>
							</div>
					  	</div>
					</form>	
				</div>
			</div>					
		</div>													
	</div>
<?php include_once('content.php');?>
	<link href="/public_source/www/assets/css/ace.min.css" rel="stylesheet" />	
	<link href="/public_source/www/assets/css/jquery.tag-editor.css" rel="stylesheet"/>
	<link  rel="stylesheet" href="/public_source/www/assets/css/jquery-confirm.css" />
<link  rel="stylesheet" href="/public_source/www/assets/css/jquery-ui.css" />
	<link  rel="stylesheet" href="/public_source/www/css/confirm.css" />
	<script src="/public_source/www/assets/js/jquery.dataTables.min.js"></script>
	<script src="/public_source/www/assets/js/jquery.dataTables.bootstrap.js"></script>
	<script src="/public_source/www/assets/js/jquery-confirm.js"></script>
<script src="/public_source/www/assets/js/jquery-ui.js"></script>
		
    <script src="/public_source/www/assets/js/bootbox.min.js"></script>  
	<script src="/public_source/www/assets/js/jquery.tag-editor.min.js"></script>
	<script src="/public_source/www/js/areas.js"></script>
	<script src="/public_source/www/My97DatePicker/WdatePicker.js"></script> 
<?php include_once('footer.php');?>	
<script type="text/javascript">
	<?php if($is_admin =='admin'){?>
	$(function () {
		var cache = {};


	});
	<?php }?>
	$(document).ready(function(){
		$("#cancel").click(function() {
			window.location.replace('/admin/user/user_list');
			return false;
		});
		var old_csg='';
		$("#check_fora").click(function (){
			var fora_id=$('#fora_id option:selected').val();
			var  keyword=$('#csg').val();

			if(keyword!='' && keyword != old_csg){
				old_csg=keyword;

			var data={fora_id:fora_id,keyword:keyword};
			$.ajax({
				url:"/admin/fora/get_fora_log",
				async: false,
				type:"post",
				data: data,
				dataType: 'json',
				success:function(data) {
					var li_html='';
					//console.log(data.length);
					if(data.length >0){
						for(var i=0;i<data.length;i++){
							li_html+='<li class="ui-menu-item" role="presentation"><a id="ui-id-'+i+'" class="ui-corner-all fora_code"data-code="'+data[i]["code"]+'" tabindex="-1">'+data[i]["fora_name"]+'/'+data[i]["code"]+'</a></li>';
						}
					}else{
						li_html='<li class="ui-menu-item" role="presentation"><a class="ui-corner-all " tabindex="-1">未查询到供位</a></li>';
					}
					$('#ui-id-1').show();
					$('#ui-id-1').html(li_html);
					$('.fora_code').click(function(){
						$('#csg').val($(this).data('code'));
						$('#ui-id-1').hide();
					});
				}
			});
			}else{
				$('#ui-id-1').show();
			}
		});
		var error_msg=document.getElementById("error_msg").value;
		if(error_msg){
			$.alert({
                title: '提示',
                content: error_msg,
                confirm: function(){
                    window.location.replace('/admin/user/user_list');
                },
				cancel:function(){
					window.location.replace('/admin/user/user_list');
				}
            });
		}
		
	});
	function xietruename(){
               if( check_name()){
                   var username = document.getElementById("username").value;
                    $("#true_name").val(username);
               }else{
                   $("#username").val('');
               }
		
	}
	function asjsch() {
        var zhuangtai = document.getElementById("zhuangtai").value;
        console.log(zhuangtai);
        if(zhuangtai =='已锁定'){
            var radio = document.getElementsByName("asjs");
            var asjs='';
            for (i=0; i<radio.length; i++) {
                if (radio[i].checked) {
                    asjs=radio[i].value
                }
            }
            console.log(asjs);
            if(asjs==1){
                for (i=0; i<radio.length; i++) {
                    if (radio[i].value ==0) {
                        asjs=radio[i].checked=true;
                    }
                }
                $.alert({
                    title: '提示',
                    content: '该会员已锁定，不能添加按锁计算产品',
                    confirm: function(){

                    }
                });

                return false;
            }
        }
    }
	function check() {
	   var username = document.getElementById("username").value;
	   var phone = document.getElementById("phone").value;
	   var address = document.getElementById("address").value;
	   var phoneReg=/^0?1[3584][0-9][0-9]{8}$/;
	   var is_admin='<?php echo $is_admin;?>';
	   var zhuangtai = document.getElementById("zhuangtai").value;
        if(zhuangtai =='已锁定'){
            var radio = document.getElementsByName("asjs");
            var asjs='';
            for (i=0; i<radio.length; i++) {
                if (radio[i].checked) {
                    asjs=radio[i].value
                }
            }
            if(asjs==1){
                for (i=0; i<radio.length; i++) {
                    if (radio[i].value ==0) {
                        asjs=radio[i].checked=true;
                    }
                }
                $.alert({
                    title: '提示',
                    content: '该会员已锁定，不能添加按锁计算产品',
                    confirm: function(){

                    }
                });

                return false;
            }
        }


	   if(username ==  null || username == '') {
	        $.alert({
                title: '提示',
                content: '登录账户不能为空',
                confirm: function(){
                    
                }
            });
	        return false;
	   }          
	   var price = parseFloat(document.getElementById("price").value);
	   var csg = document.getElementById("csg").value;
            
            if(isNaN(price)){
                price=0;
            }
		if(is_admin!='admin'){
			if(price ==0 ||price ==  null || price == '') {
				$.alert({
					title: '提示',
					content: '价格不能小于0',
					confirm: function(){
						
					}
				});
				return false;
			}
		}
		if(price >1000){
            $.alert({
                title: '提示',
                content: '价格不能大于1000',
                confirm: function(){

                }
            });
            return false;
        }
	   
	   if(csg ==  null || csg == '') {
	        $.alert({
                title: '提示',
                content: '供位不能为空',
                confirm: function(){
                    
                }
            });
	        return false;
	   }
		<?php if($is_admin =='admin'){ ?>
		var fora_id=$('#fora_id option:selected').val();
		   var data={csg:csg,fora_id:fora_id};
		   var bool=true;
		   $.ajax({
			   url:"/admin/fora/check_fora_log",
			   async: false,
			   type:"post",
			   data: data,
			   dataType: 'json',
			   success:function(data) {
				   bool = data;
			   }
		   });
		   if(!bool) {
			   $.alert({
				   title: '提示',
				   content:'供位编号不存在或已被使用',
				   confirm: function(){
				   }
			   });
			   return false;
		   }else{
			   return true;
		   }
		<?php }?>
          
	   return true;
	}
        function check_name(){
            var username = document.getElementById("username").value;
             var data={username:username};
            if(username == null || username==''){
                $.alert({
                    title: '提示',
                    content:'登录名不能为空',
                    confirm: function(){
                    }
                });
                 return false;
            }else{
                var bool=true;
                $.ajax({
			url:"/admin/user/check_name2",
			async: false,
			type:"post",
			data: data,
			dataType: 'json',
			success:function(data) {
				bool = data;
			}	
		});
                if(!bool) {
		   	$.alert({
			    title: '提示',
			    content:'登录名不能重复',
			    confirm: function(){
			    }
			});
			return false;	
		}else{
                    return true;
                }
            }
            
        }
</script>
<ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all" id="ui-id-1" tabindex="0" style="top: 239px; left: 24%; display: none; width: 23%;"></ul>